#include <iostream>
#include "array.h"

Array::Array(const size_t tsize)
{
	first = new int[tsize];
	mem_size = tsize;
	size = 0;
}

int Array::get(const size_t index) const
{
	if (index > size-1)
	{
		std::cout << "Wrong index!!!!" << std::endl;
		return 0;
	}
	return first[index];
}

void Array::set(const size_t index, const int value)
{
	if (index > size-1)
	{
		std::cout << "Wrong index!!!!" << std::endl;
		return;
	}
	first[index] = value;	
}

Array::~Array()
{
	delete[] first;
}

Array::Array(const Array& another)
{
	first = new int[another.mem_size];
	size = another.size;
	mem_size = another.mem_size;		
	for (size_t i = 0; i < size; ++i)
	{
		first[i] = another.first[i];
	}
}

Array& Array::operator= (const Array& another)
{
	Array tmp(another);
	swap(tmp);
	return *this;
}

void Array::swap(Array& another)
{
	std::swap(size,another.size);
	std::swap(mem_size,another.mem_size);
	std::swap(first,another.first);
}

size_t Array::get_size() const
{
	return size;
}

void Array::make_big_copy()
{
	Array big(mem_size*2);
	big.size = size;
	for (size_t i = 0; i < size; ++i)
	{
		big.first[i] = first[i];
	}
	swap(big);
}

void Array::push_back(const int value)
{
	if (size >= mem_size)
	{
		make_big_copy();
	}
	first[size] = value;
	size++;				
}

size_t Array::get_mem_size() const
{
	return mem_size;
}



